package com.aeroyun.macross.modular.countryside.controller;

import com.aeroyun.macross.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.aeroyun.macross.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.aeroyun.macross.modular.system.model.Town;
import com.aeroyun.macross.modular.countryside.service.ITownService;

/**
 * 乡镇管理控制器
 *
 * @author fengshuonan
 * @Date 2018-08-16 23:28:19
 */
@Controller
@RequestMapping("/town")
public class TownController extends BaseController {

    private String PREFIX = "/countryside/town/";

    @Autowired
    private ITownService townService;

    /**
     * 跳转到乡镇管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "town.html";
    }

    /**
     * 跳转到添加乡镇管理
     */
    @RequestMapping("/town_add")
    public String townAdd() {
        return PREFIX + "town_add.html";
    }

    /**
     * 跳转到修改乡镇管理
     */
    @RequestMapping("/town_update/{townId}")
    public String townUpdate(@PathVariable Integer townId, Model model) {
        Town town = townService.selectById(townId);
        model.addAttribute("item",town);
        LogObjectHolder.me().set(town);
        return PREFIX + "town_edit.html";
    }

    /**
     * 获取乡镇管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	
    
    	
        return townService.selectList(null);
    }

    /**
     * 新增乡镇管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Town town) {
        townService.insert(town);
        return SUCCESS_TIP;
    }

    /**
     * 删除乡镇管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer townId) {
        townService.deleteById(townId);
        return SUCCESS_TIP;
    }

    /**
     * 修改乡镇管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Town town) {
        townService.updateById(town);
        return SUCCESS_TIP;
    }

    /**
     * 乡镇管理详情
     */
    @RequestMapping(value = "/detail/{townId}")
    @ResponseBody
    public Object detail(@PathVariable("townId") Integer townId) {
        return townService.selectById(townId);
    }
}
